package app.modules.infrastructure.profile.persistence.dao;

import app.modules.common.util.db.FirstOnlyPage;
import app.modules.common.util.db.PageDisabled;
import app.modules.infrastructure.profile.persistence.entity.ProfileValueEO;
import app.modules.infrastructure.profile.persistence.mapper.ProfileValueMapper;
import jasmine.framework.common.util.CollectionUtil;
import jasmine.framework.database.mybatisplus.dao.BaseI18nEntityDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author mh.z
 */
@Repository
public class ProfileValueDAO extends BaseI18nEntityDAO<ProfileValueMapper, ProfileValueEO> {

    /**
     * 获取指定的配置值
     *
     * @param profileName
     * @param tenantId
     * @param userId
     * @param requiredOnly
     * @param enabledOnly
     * @return
     */
    public List<ProfileValueEO> listProfileValuesByProfileName(String profileName, Long tenantId, Long userId,
                                                               boolean requiredOnly, boolean enabledOnly) {
        return baseMapper.pageProfileValuesByProfileName(profileName, tenantId, userId,
                requiredOnly, enabledOnly, new PageDisabled());
    }

    /**
     * 获取指定的配置值
     *
     * @param tenantId
     * @param userId
     * @param profileName
     * @return
     */
    public ProfileValueEO getProfileValueByProfileName(String profileName, Long tenantId, Long userId) {
        List<ProfileValueEO> resultList = baseMapper.pageProfileValuesByProfileName(profileName,
                tenantId, userId, true, true, new FirstOnlyPage());

        return CollectionUtil.getFirst(resultList);
    }

}
